﻿using UnityEngine;
using System.Collections;

public class Cat : MonoBehaviour {

    public float xOffset = -2.0f;
    public float yOffset = -3.6f;
    public int columnIndex;
    public int rowIndex;
    public GameController game;

    public void UpdatePosition()
    {
        this.transform.position = new Vector3(columnIndex * 0.5f + xOffset + ((rowIndex % 2 == 0) ? 0.5f : 0), rowIndex * 0.5f + yOffset, 0);
    }

    public void MoveCat(int columnIndex, int rowIndex)
    {
        Debug.Log(gameObject.name);
        Debug.Log(this.name);
        this.rowIndex = rowIndex;
        this.columnIndex = columnIndex;
        UpdatePosition();
    }

    public void RandomStep(ArrayList steps)
    {
        if (steps.Count == 0)
        {
            Debug.Log("你取得了胜利！");
            game.started = false;
            game.victory.SetActive(true);
            game.replay.SetActive(true);
            return;
        }
        int randomIndex = (int)Random.Range(0, steps.Count - 1);
        Debug.Log("随机数是" + randomIndex);
        Vector2 vector2 = (Vector2)steps[randomIndex];
        MoveCat((int)vector2.y, (int)vector2.x);
        if (this.columnIndex == 0 || this.columnIndex == game.columnNum - 1 || this.rowIndex == 0 || this.rowIndex == game.rowNum - 1)
        {
            Debug.Log("你放走了神经猫！！");
            game.failed.SetActive(true);
            game.replay.SetActive(true);
            return;
        }
    }
}
